{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cbc6a1dc",
   "metadata": {},
   "source": [
    "# 海龟绘图的基本操作"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a2d757f",
   "metadata": {},
   "source": [
    "## 现实中的绘画步骤\n",
    "\n",
    "<font style=\"color:blue;font-size:18px\"> 1. 准备一张空白的<b style=\"color:red;font-size:18px\">画布</b>或纸张</font>\n",
    "<br>\n",
    "<font style=\"color:blue;font-size:18px\"> 2. 挑选一支心仪的<b style=\"color:red;font-size:18px\">笔</b>（或多种颜色的笔）</font>\n",
    "<br>\n",
    "<font style=\"color:blue;font-size:18px\"> 3. 发挥你的创意与巧手，开始在纸上<b style=\"color:red;font-size:18px\">绘制</b>出属于你的绘画作品</font>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0192803",
   "metadata": {},
   "source": [
    "## 电脑绘图的基本知识（结合以上绘画步骤）\n",
    "\n",
    "<font style=\"color:red;font-size:18px\"> 1.画布（canvas）</font>\n",
    "<br>\n",
    "<font style=\"color:red;font-size:18px\"> 2.画笔（pen）</font>\n",
    "<br>\n",
    "<font style=\"color:red;font-size:18px\"> 3.绘图命令（pen）</font>\n",
    "<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f41146f",
   "metadata": {},
   "source": [
    "<font style=\"color:red;font-size:20px\"> Turtle 是 Python 内置的绘图模块，俗称海龟作图，Turtle 提供一些简单的绘图工具。<br>我们只需要 import turtle，就可以在 Python 中使用海龟作图了。</font>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ef18394d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入海龟绘图包\n",
    "# from ipyturtle import Turtle as t\n",
    "from turtle_utils import ignore_terminator_exception\n",
    "from turtle import *\n",
    "# import turtle as t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "01d28512",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置画布大小(canvwidth：宽(单位像素), canvheight：高(单位像素), bg：背景颜色)\n",
    "screensize(canvwidth=800, canvheight=600, bg=\"white\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "dd4fa9ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "Pen()\n",
    "done()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "TurtleScreen._RUNNING = True  # 解决 turtle.Terminator 异常的问题\n",
    "begin_fill()\n",
    "pensize(10) # 设置画笔的宽度；\n",
    "pencolor(\"red\") # 设置画笔颜色\n",
    "hideturtle() # 隐藏画笔的turtle形状\n",
    "showturtle() # 显示画笔的turtle形状\n",
    "circle(120,180)\n",
    "clear() # 清空turtle窗口，但是turtle的位置和状态不会改变\n",
    "circle(120,180) \n",
    "# reset() # 清空窗口，重置turtle状态为起始状态\n",
    "# \n",
    "end_fill()\n",
    "done()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 画布的坐标"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# circle(50) # 整圆;\n",
    "# circle(50,steps=3) # 三角形;\n",
    "# circle(120, 180) # 半圆\n",
    "# turtle.Pen()\n",
    "circle(radius=50)\n",
    "# 描述: 以给定半径画圆\n",
    "# 参数:\n",
    "# radius(半径); 半径为正(负),表示圆心在画笔的左边(右边)画圆\n",
    "# extent(弧度) (optional);\n",
    "# steps (optional) (做半径为radius的圆的内切正多边形,多边形边数为steps)\n",
    "done()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "id": "69abaf9b",
   "metadata": {},
   "source": [
    "## 演示案列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f9451fdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绘画终止\n"
     ]
    }
   ],
   "source": [
    "from turtle_demo import party_flag\n",
    "# 绘制党旗\n",
    "party_flag()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9d80ac53",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绘画终止\n"
     ]
    }
   ],
   "source": [
    "from turtle_demo import tree\n",
    "# 绘制树\n",
    "tree() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7a7d5d50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绘画终止\n"
     ]
    }
   ],
   "source": [
    "from turtle_demo import doraemon\n",
    "## 绘制哆啦A梦（机器猫）\n",
    "doraemon()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "55456935",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绘画终止\n"
     ]
    }
   ],
   "source": [
    "from turtle_demo import draw_mystical_spiral\n",
    "## 绘制螺旋\n",
    "draw_mystical_spiral() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b764a345",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "绘画终止\n"
     ]
    }
   ],
   "source": [
    "from turtle_demo import olympic_rings\n",
    "# 绘制奥运五环\n",
    "olympic_rings()  "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}